// 递归实现深拷贝
const deepClone = obj => {
  let newObj = Array.isArray(obj) ? [] : {};
  if (obj && typeof obj === 'object') {
    for (const key in obj) {
      if (obj.hasOwnProperty(key)) {
        if (obj[key] && typeof obj[key] === 'object') {
          newObj[key] = deepClone(obj[key]);
        } else {
          // 如果不是对象直接拷贝
          newObj[key] = obj[key];
        }
      }
    }
  }
  return newObj
}
const richGirl = {
  name: '小丽',
  car: ['宝马', '奥迪', '保时捷'],
  deive: function(){},
  age: undefined
}
const richBoy = deepClone(richGirl);
console.log('------richBoy', richBoy);
richBoy.deive = {
  name: 'name',
  obj: {
    title: '测试',
    objName: ['name', 'title']
  }
};
richBoy.name = '小明';
richBoy.car = ['共享单车', '膜拜'];
richBoy.age = 20;
console.log('---richGirl-----', richGirl);
console.log('---richBoy------', richBoy)